#define _CRT_SECURE_NO_WARNINGS 1


#include"Date.h"

int is_year(int y)
{
	if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
		return 1;
	return 0;
}
	Date::Date(int year , int month , int day )
	{
		_year = year;
		_month = month;
		_day = day;
	}
	Date::Date(const Date& d)
	{
		cout << "Date::Date(const Date& d)" << endl;
		_year = d._year;
		_month = d._month;
		_day = d._day;
	}
		
	Date& Date::operator+=(int day)
	{
		_day += day;
		while (_day > GetMonthDay(_year, _month))
		{
			_day -= GetMonthDay(_year, _month);
			_month++;
			if (_month == 13)
			{
				_year++;
				_month = 1;
			}
		}
		return *this;
	}

	Date Date::operator+(int day)
	{
		Date tem = *this;
		tem += day;
		return tem;
	}

	Date& Date::operator-=(int day)
	{
		_day -=day;
		while (_day < 0)
		{
			_month--;
			if (_month == 0)
			{
				_year--;
				_month = 12;
			}
			_day += GetMonthDay(_year, _month);
		}
		return *this;
	}

	Date Date::operator-(int day)
	{
		Date tem = *this;
		tem -= day;
		return tem;
	}


	//ǰ  ++
	Date& Date::operator++()
	{
		*this += 1;
		return *this;
	}

	//    ++
	//int ֻ  һ    ־         Ǻ  õ --  û  ʵ      
	Date Date::operator++(int)
	{
		Date tem = *this;
		*this += 1;
		return tem;
	}

	//ǰ  --
	Date& Date::operator--()
	{
		*this -= 1;
		return *this;
	}

	//    --
	Date Date::operator--(int)
	{
		Date tem = *this;
		*this -= 1;
		return tem;
	}

	//    -    
	int Date:: operator-(const Date& d)
	{
		Date max = *this;
		Date min = d;
		int n = 0;
		int flag = 1;
		if (max < min)
		{
			max = d;
			min = *this;
			flag = -1;
		}

		while (min!=max)
		{
			++min;
			++ n;
		}
		return n*flag;                                                 
	}



	//  ֵ         
	Date& Date:: operator=(const Date& d)
	{
		_year = d._year;
		_month = d._month;
		_day = d._day;
		return *this;
	}

	bool Date::operator<(const Date& d)
	{
		if (_year < d._year)
			return true;

		else if (_year == d._year)
		{
			if (_month < d._month)
				return true;

			else if (_month == d._month)
				return _day < d._day;
		}
		return false;
	}

	bool Date::operator==(const Date& d)
	{
		return _year == d._year
			&& _month == d._month
			&& _day == d._day;
	}

	bool Date::operator<=(const Date& d)
	{
		return *this < d && *this == d;
	}
	bool Date::operator>(const Date& d)
	{
		return !(*this <= d);
	}
	bool Date::operator>=(const Date& d)
	{
		return !(*this <d);
	}
	bool Date::operator!=(const Date& d)
	{
		return !(*this == d);
	}

	void Date::print()
	{
		cout << _year << "-" << _month << "-" << _day << endl;
	}
	Date::~Date()
	{
		//cout << "Date::~Date()" << endl;

	}

	ostream& operator<<(ostream& out, const Date& d)
	{
		out << d._year << "  " << d._month << "  " << d._day << endl;
		return out;
	}

	istream& operator>>(istream& in, Date& d)
	{
		cout << "          :" << endl;

		in >> d._year >> d._month >> d._day;

		return in;
	}


